package com.jzo2o.foundations.controller.operation;


import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * @Author: Zuo
 * @Date: 2025/3/20 19:34
 * @Description:
 **/
@Validated
@RestController("operationServerController")
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 区域服务相关接口")
public class ServeController {

    @Resource
    private IServeService serveService;

    @GetMapping("/page")
    @ApiOperation(value = "分页查询区域服务")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO servePageQueryReqDTO){
        return serveService.page(servePageQueryReqDTO);
    }

    @PostMapping("/batch")
    @ApiOperation(value = "区域服务批量新增")
    public void batch(@RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTOList){
        serveService.batch(serveUpsertReqDTOList);
    }

    /**
     * 区域服务修改价格
     * @param id
     * @param price
     */
    @PutMapping("/{id}")
    @ApiOperation(value = "区域服务修改价格")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "区域服务id", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "price", value = "区域服务 价格", required = true, dataTypeClass = Long.class)
    })
    public void update(@PathVariable("id") Long id,@RequestParam("price") BigDecimal price){
        serveService.updatePrice(id,price);
    }

    /**
     * 区域服务上架
     */
    @PutMapping("/onSale/{id}")
    @ApiOperation(value = "区域服务上架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "区域服务id", required = true, dataTypeClass = Long.class)
    })
    public void onSale(@PathVariable("id") Long id){
        serveService.onSale(id);
    }

    /**
     * 区域下架服务
     */
    @PutMapping("/offSale/{id}")
    @ApiOperation(value = "区域服务下架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "区域服务id", required = true, dataTypeClass = Long.class)
    })
    public void offSale(@PathVariable("id") Long id){
        serveService.offSale(id);
    }

}
